#include <iostream>
#include <map>
#include <string>
using namespace std;


int find(int *f,int n){
	if(f[n] == n)
		return n;
	f[n] = find(f,f[n]);
	return f[n];
}

int main(){
	int n,m,k;
	cin>>n>>m;
	int f[n];
	for(int i=0;i<n;i++)
		f[i] = i;
	map<string,int> name;
	for(int i=0;i<n;i++){
		string s;
		cin>>s;
		name[s]=i;
	}
	for(int i=0;i<m;i++){
		string s1,s2;
		cin>>s1>>s2;
		f[find(f,name[s1])] = find(f,name[s2]);
	}
	cin>>k;
	for(int i=0;i<k;i++){
		string s1,s2;
		cin>>s1>>s2;
		if(find(f,name[s1]) == find(f,name[s2]))
			cout<<"Yes."<<endl;
		else
			cout<<"No."<<endl;
	}
	return 0;
}
